from abc import ABC


class DataConverter(ABC):
    @classmethod
    def convert_results_to_objects(cls, results, obj_class):
        objects = []
        for row in results:
            # 假设row是一个位置参数的元组或列表
            obj = obj_class(*row)
            objects.append(obj)
        return objects

    @classmethod
    def convert_objects_to_json(cls, objects):
        json_list = []
        for obj in objects:
            json_dict = cls.process_object_to_dict(obj)
            json_list.append(json_dict)
        return json_list

    @classmethod
    def process_object_to_dict(cls, obj):
        """将对象转换为字典，并允许子类重写以添加自定义处理"""
        obj_dict = obj.__dict__.copy()
        obj_dict = cls.post_process_dict(obj_dict)
        return obj_dict

    @classmethod
    def post_process_dict(cls, obj_dict):
        """允许子类重写此方法以对字典进行后处理"""
        return obj_dict  # 默认不进行任何处理